package com.bw.goods_module.home.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.blankj.utilcode.util.ConvertUtils;
import com.bw.goods_module.R;
import com.bw.goods_module.home.HomeBannerEntity;
import com.bw.imgload_sdk.LoadImgUtils;

import java.util.List;

public class HomeRecommandAdapter extends PagerAdapter {
    private List<HomeBannerEntity> list;
    public HomeRecommandAdapter(List<HomeBannerEntity> list){
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = LayoutInflater.from(container.getContext())
                .inflate(R.layout.itme_home_top,container,false);
        container.addView(view);
        ImageView home_top_img = view.findViewById(R.id.home_top_img);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT
                , LinearLayout.LayoutParams.MATCH_PARENT);
        home_top_img.setLayoutParams(lp);
        LoadImgUtils.loadMatchImg(list.get(position).imgUrl,home_top_img);
        return view;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        View view = (View) object;
        container.removeView(view);
    }
}
